<?php
namespace app\service\controller;

use app\common\controller\ServiceOauth;
use external\SFTools;
use think\App;

class Dispatch extends ServiceOauth {

    public function initialize(){
        parent::initialize();
    }
    
    /**
     * 获取制令信息列表
     * @param   string  keyword         关键字
     * @param   int     page            页码
     * @param   int     size            每页大小
     * @return  json                    Json对象 ( status / code / msg / data )
     */
    public function getMoList(){
        $keyword = htmlspecialchars(input("post.keyword"));
        $fPlanDate = htmlspecialchars(input("post.fPlanDate"));
        $fStartDate = htmlspecialchars(input("post.fStartDate"));
        $fEndDate = htmlspecialchars(input("post.fEndDate"));
        $cw = htmlspecialchars(input("post.cw"));
        $ct = htmlspecialchars(input("post.ct"));
        $wg = htmlspecialchars(input("post.wg"));
        $page = htmlspecialchars(input("post.page"));
        $size = htmlspecialchars(input("post.size"));

        $dispatchLogic = new \backend\logic\DispatchLogic;
        $result = $dispatchLogic->getMoList($keyword, $fPlanDate, $fStartDate, $fEndDate, $cw, $ct, $wg, $page, $size);

        if (empty($result['error_code'])) {
            return SFTools::pullJson(1, NULL, $result);
        } else {
            return SFTools::pullJson(-1, $result['error_code'], $result['data']);
        }
    }
    
    /**
     * 获取制令信息列表的数据总条数
     * @param   string  keyword         关键字
     * @return  json                    Json对象 ( status / code / msg / data )
     */
    public function getMoListCount(){
        $keyword = htmlspecialchars(input("post.keyword"));
        $fPlanDate = htmlspecialchars(input("post.fPlanDate"));
        $fStartDate = htmlspecialchars(input("post.fStartDate"));
        $fEndDate = htmlspecialchars(input("post.fEndDate"));
        $cw = htmlspecialchars(input("post.cw"));
        $ct = htmlspecialchars(input("post.ct"));
        $wg = htmlspecialchars(input("post.wg"));
        
        $dispatchLogic = new \backend\logic\DispatchLogic;
        $result = $dispatchLogic->getMoListCountBuyKeyword($keyword, $fPlanDate, $fStartDate, $fEndDate, $cw, $ct, $wg);
        
        if (empty($result['error_code'])) {
            return SFTools::pullJson(1, NULL, $result);
        } else {
            return SFTools::pullJson(-1, $result['error_code'], $result['data']);
        }
    }
    
    /**
     * 修改生产工作记录
     * @param   string  fMONo           制令编号
     * @param   int  fGoodsID           商品标识
     * @param   int  sort               排序权重
     * @param   int  fStep01            床网入库数
     * @param   int  fStep02            车缝完工数
     * @param   int  fStep03            床网打底数
     * @param   int  fStep04            围边派工数
     * @param   int  fStep05            围边完工数
     * @return  json                    Json对象 ( status / code / msg / data )
     */
    public function editMoInfo(){
        $fMONo = htmlspecialchars(input("post.fMONo"));
        $fGoodsID = htmlspecialchars(input("post.fGoodsID"));
        $sort = htmlspecialchars(input("post.sort"));
        $fPlanCountCw = htmlspecialchars(input("post.fPlanCountCw"));
        
        $dispatchLogic = new \backend\logic\DispatchLogic;
        $result = $dispatchLogic->editMoInfoBuyfMONoANDfGoodsID($fMONo, $fGoodsID, $sort, $fPlanCountCw);
        
        if (empty($result['error_code'])) {
            return SFTools::pullJson(1, NULL, $result);
        } else {
            return SFTools::pullJson(-1, $result['error_code'], $result['data']);
        }
    }
    
    /**
     * 获取未核床网数组
     * @param   无
     */
    public function getNotUseCW(){
        $dispatchLogic = new \backend\logic\DispatchLogic;
        $result = $dispatchLogic->getNotUseCW();
        
        if (empty($result['error_code'])) {
            return SFTools::pullJson(1, NULL, $result);
        } else {
            return SFTools::pullJson(-1, $result['error_code'], $result['data']);
        }
    }
    
    /**
     * 获取未核床网数组
     * @param   无
     */
    public function toWriteOff(){
        $fMONo = htmlspecialchars(input("post.fMONo"));
        $fGoodsID = htmlspecialchars(input("post.fGoodsID"));
        $fQtyCW = htmlspecialchars(input("post.fQtyCW"));
        $dispatchLogic = new \backend\logic\DispatchLogic;
        $result = $dispatchLogic->toWriteOff($fMONo, $fGoodsID, $fQtyCW);
        
        if (empty($result['error_code'])) {
            return SFTools::pullJson(1, NULL, $result);
        } else {
            return SFTools::pullJson(-1, $result['error_code'], $result['data']);
        }
    }
    /**
     * 获取未核床网数组
     * @param   无
     */
    public function toUnWriteOff(){
        $fMONo = htmlspecialchars(input("post.fMONo"));
        $fGoodsID = htmlspecialchars(input("post.fGoodsID"));
        $dispatchLogic = new \backend\logic\DispatchLogic;
        $result = $dispatchLogic->toUnWriteOff($fMONo, $fGoodsID);
        
        if (empty($result['error_code'])) {
            return SFTools::pullJson(1, NULL, $result);
        } else {
            return SFTools::pullJson(-1, $result['error_code'], $result['data']);
        }
    }
}
